<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>nih: basic/stats.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">nih
   &#160;<span id="projectnumber">0.5</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('stats_8h.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">basic/stats.h</div>  </div>
</div>
<div class="contents">
<a href="stats_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * Copyright (c) 2010-2011, NVIDIA Corporation</span>
<a name="l00003"></a>00003 <span class="comment"> * All rights reserved.</span>
<a name="l00004"></a>00004 <span class="comment"> *</span>
<a name="l00005"></a>00005 <span class="comment"> * Redistribution and use in source and binary forms, with or without</span>
<a name="l00006"></a>00006 <span class="comment"> * modification, are permitted provided that the following conditions are met:</span>
<a name="l00007"></a>00007 <span class="comment"> *   * Redistributions of source code must retain the above copyright</span>
<a name="l00008"></a>00008 <span class="comment"> *     notice, this list of conditions and the following disclaimer.</span>
<a name="l00009"></a>00009 <span class="comment"> *   * Redistributions in binary form must reproduce the above copyright</span>
<a name="l00010"></a>00010 <span class="comment"> *     notice, this list of conditions and the following disclaimer in the</span>
<a name="l00011"></a>00011 <span class="comment"> *     documentation and/or other materials provided with the distribution.</span>
<a name="l00012"></a>00012 <span class="comment"> *   * Neither the name of NVIDIA Corporation nor the</span>
<a name="l00013"></a>00013 <span class="comment"> *     names of its contributors may be used to endorse or promote products</span>
<a name="l00014"></a>00014 <span class="comment"> *     derived from this software without specific prior written permission.</span>
<a name="l00015"></a>00015 <span class="comment"> *</span>
<a name="l00016"></a>00016 <span class="comment"> * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND</span>
<a name="l00017"></a>00017 <span class="comment"> * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED</span>
<a name="l00018"></a>00018 <span class="comment"> * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE</span>
<a name="l00019"></a>00019 <span class="comment"> * DISCLAIMED. IN NO EVENT SHALL &lt;COPYRIGHT HOLDER&gt; BE LIABLE FOR ANY</span>
<a name="l00020"></a>00020 <span class="comment"> * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES</span>
<a name="l00021"></a>00021 <span class="comment"> * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;</span>
<a name="l00022"></a>00022 <span class="comment"> * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND</span>
<a name="l00023"></a>00023 <span class="comment"> * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</span>
<a name="l00024"></a>00024 <span class="comment"> * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS</span>
<a name="l00025"></a>00025 <span class="comment"> * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
<a name="l00026"></a>00026 <span class="comment"> */</span>
<a name="l00027"></a>00027 
<a name="l00032"></a>00032 <span class="preprocessor">#pragma once</span>
<a name="l00033"></a>00033 <span class="preprocessor"></span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &lt;cmath&gt;</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include &lt;limits&gt;</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include &lt;vector&gt;</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include &lt;nih/basic/types.h&gt;</span>
<a name="l00038"></a>00038 
<a name="l00039"></a>00039 <span class="keyword">namespace </span>nih {
<a name="l00040"></a>00040 
<a name="l00044"></a>00044 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
<a name="l00045"></a><a class="code" href="structnih_1_1_stats.html">00045</a> <span class="keyword">struct </span><a class="code" href="structnih_1_1_stats.html">Stats</a>
<a name="l00046"></a>00046 {
<a name="l00049"></a><a class="code" href="structnih_1_1_stats.html#a6e6d6f04266848eda17225b1f0402953">00049</a>         <a class="code" href="structnih_1_1_stats.html#a6e6d6f04266848eda17225b1f0402953">Stats</a>() :
<a name="l00050"></a>00050                 m_sum(T(0)),
<a name="l00051"></a>00051                 m_sum_sq(T(0)),
<a name="l00052"></a>00052                 m_min(std::numeric_limits&lt;T&gt;::<a class="code" href="structnih_1_1_stats.html#a731ffdbad86052f9189e5dd7f89dcaba">max</a>()),
<a name="l00053"></a>00053                 m_max(std::numeric_limits&lt;T&gt;::<a class="code" href="structnih_1_1_stats.html#a9004ea55168fe069477102bbc326fd30">min</a>()),
<a name="l00054"></a>00054                 m_count(0u) {}
<a name="l00055"></a>00055 
<a name="l00060"></a><a class="code" href="structnih_1_1_stats.html#a882a0ca9d48e403ff6026936b669b1bb">00060</a>         <a class="code" href="structnih_1_1_stats.html#a6e6d6f04266848eda17225b1f0402953">Stats</a>(<span class="keyword">const</span> T <a class="code" href="structnih_1_1_stats.html#a9004ea55168fe069477102bbc326fd30">min</a>, <span class="keyword">const</span> T <a class="code" href="structnih_1_1_stats.html#a731ffdbad86052f9189e5dd7f89dcaba">max</a>) :
<a name="l00061"></a>00061                 m_sum(T(0)),
<a name="l00062"></a>00062                 m_sum_sq(T(0)),
<a name="l00063"></a>00063                 m_min(max),
<a name="l00064"></a>00064                 m_max(min),
<a name="l00065"></a>00065                 m_count(0u) {}
<a name="l00066"></a>00066 
<a name="l00070"></a><a class="code" href="structnih_1_1_stats.html#a3cab0803fe20106b282de8d2e3dfcb3d">00070</a>     <span class="keywordtype">void</span> <a class="code" href="structnih_1_1_stats.html#a3cab0803fe20106b282de8d2e3dfcb3d">operator+= </a>(<span class="keyword">const</span> T v)
<a name="l00071"></a>00071         {
<a name="l00072"></a>00072                 m_sum += v;
<a name="l00073"></a>00073                 m_sum_sq += v*v;
<a name="l00074"></a>00074                 m_count++;
<a name="l00075"></a>00075                 m_min = <a class="code" href="structnih_1_1_stats.html#a9004ea55168fe069477102bbc326fd30">std::min</a>( v, m_min );
<a name="l00076"></a>00076                 m_max = <a class="code" href="structnih_1_1_stats.html#a731ffdbad86052f9189e5dd7f89dcaba">std::max</a>( v, m_max );
<a name="l00077"></a>00077         }
<a name="l00081"></a><a class="code" href="structnih_1_1_stats.html#aaddb68f2119f81f83c94ea2afe3e2aa0">00081</a>     <span class="keywordtype">void</span> <a class="code" href="structnih_1_1_stats.html#a3cab0803fe20106b282de8d2e3dfcb3d">operator+= </a>(<span class="keyword">const</span> <a class="code" href="structnih_1_1_stats.html">Stats&lt;T&gt;</a>&amp; v)
<a name="l00082"></a>00082         {
<a name="l00083"></a>00083                 m_sum    += v.m_sum;
<a name="l00084"></a>00084                 m_sum_sq += v.m_sum_sq;
<a name="l00085"></a>00085                 m_count  += v.m_count;
<a name="l00086"></a>00086                 m_min = <a class="code" href="structnih_1_1_stats.html#a9004ea55168fe069477102bbc326fd30">std::min</a>( v.m_min, m_min );
<a name="l00087"></a>00087                 m_max = <a class="code" href="structnih_1_1_stats.html#a731ffdbad86052f9189e5dd7f89dcaba">std::max</a>( v.m_max, m_max );
<a name="l00088"></a>00088         }
<a name="l00089"></a>00089 
<a name="l00092"></a><a class="code" href="structnih_1_1_stats.html#af01f7f8dd7a128d55d408481e72d6615">00092</a>         T                       <a class="code" href="structnih_1_1_stats.html#af01f7f8dd7a128d55d408481e72d6615">avg</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_count ? m_sum / T(m_count) : T(0); }
<a name="l00095"></a><a class="code" href="structnih_1_1_stats.html#af08c497de2da6e0fb9f1e0e58cc7d7d5">00095</a>         T                       <a class="code" href="structnih_1_1_stats.html#af08c497de2da6e0fb9f1e0e58cc7d7d5">sum</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_sum; }
<a name="l00098"></a><a class="code" href="structnih_1_1_stats.html#aa5f3bd77225bd4f92d7dfbf5b76eb2d0">00098</a>         T                       <a class="code" href="structnih_1_1_stats.html#aa5f3bd77225bd4f92d7dfbf5b76eb2d0">var</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_count ? (m_sum_sq - m_sum) / T(m_count) : T(0); }
<a name="l00101"></a><a class="code" href="structnih_1_1_stats.html#af9a03822086e7f6f77cdb8d49bc191ad">00101</a>         T                       <a class="code" href="structnih_1_1_stats.html#af9a03822086e7f6f77cdb8d49bc191ad">sigma</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> T( sqrt( <a class="code" href="structnih_1_1_stats.html#aa5f3bd77225bd4f92d7dfbf5b76eb2d0">var</a>() ) ); }
<a name="l00104"></a><a class="code" href="structnih_1_1_stats.html#a9004ea55168fe069477102bbc326fd30">00104</a>         T                       <a class="code" href="structnih_1_1_stats.html#a9004ea55168fe069477102bbc326fd30">min</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_min; }
<a name="l00107"></a><a class="code" href="structnih_1_1_stats.html#a731ffdbad86052f9189e5dd7f89dcaba">00107</a>         T                       <a class="code" href="structnih_1_1_stats.html#a731ffdbad86052f9189e5dd7f89dcaba">max</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_max; }
<a name="l00110"></a><a class="code" href="structnih_1_1_stats.html#a5e68da5d70cd31130bca00c4224fe740">00110</a>         <span class="keywordtype">long</span> <span class="keywordtype">long</span>       <a class="code" href="structnih_1_1_stats.html#a5e68da5d70cd31130bca00c4224fe740">count</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_count; }
<a name="l00111"></a>00111 
<a name="l00112"></a>00112         T                       m_sum;
<a name="l00113"></a>00113         T                       m_sum_sq;
<a name="l00114"></a>00114         T                       m_min;
<a name="l00115"></a>00115         T                       m_max;
<a name="l00116"></a>00116         <span class="keywordtype">long</span> <span class="keywordtype">long</span>       m_count;
<a name="l00117"></a>00117 };
<a name="l00118"></a>00118 
<a name="l00126"></a>00126 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
<a name="l00127"></a><a class="code" href="structnih_1_1_histogram.html">00127</a> <span class="keyword">struct </span><a class="code" href="structnih_1_1_histogram.html">Histogram</a>
<a name="l00128"></a>00128 {
<a name="l00129"></a>00129         <span class="keyword">typedef</span> <a class="code" href="structnih_1_1_stats.html">Stats&lt;T&gt;</a> <a class="code" href="structnih_1_1_stats.html">Stats_type</a>;
<a name="l00130"></a>00130 
<a name="l00133"></a><a class="code" href="structnih_1_1_histogram.html#a02fc7d53135317aa09987e844dc12b62">00133</a>         <a class="code" href="structnih_1_1_histogram.html#a02fc7d53135317aa09987e844dc12b62">Histogram</a>() {}
<a name="l00134"></a>00134 
<a name="l00139"></a><a class="code" href="structnih_1_1_histogram.html#a3ec4838b404f190ba70268a653ceb1b0">00139</a>         <a class="code" href="structnih_1_1_histogram.html#a02fc7d53135317aa09987e844dc12b62">Histogram</a>(
<a name="l00140"></a>00140                 <span class="keyword">const</span> <a class="code" href="structnih_1_1_stats.html">Stats_type</a>&amp; stats,
<a name="l00141"></a>00141                 <span class="keyword">const</span> uint32 bins) :
<a name="l00142"></a>00142                 m_stats( stats ),
<a name="l00143"></a>00143                 m_bins( bins ),
<a name="l00144"></a>00144                 m_var(T(0)) {}
<a name="l00145"></a>00145 
<a name="l00150"></a><a class="code" href="structnih_1_1_histogram.html#a2019e21e8331552e11868f2ebb7e88ed">00150</a>         uint32 <a class="code" href="structnih_1_1_histogram.html#a2019e21e8331552e11868f2ebb7e88ed">bin</a>(<span class="keyword">const</span> T v)<span class="keyword"> const</span>
<a name="l00151"></a>00151 <span class="keyword">        </span>{
<a name="l00152"></a>00152                 <span class="keyword">const</span> <span class="keywordtype">double</span> x = double(m_bins.size()) * <a class="code" href="group__vectors.html#gab2b34b1991185fc29890973777b60e54">std::max</a>( <span class="keywordtype">double</span>(v - m_stats.<a class="code" href="structnih_1_1_stats.html#a9004ea55168fe069477102bbc326fd30">min</a>()), 0.0 ) / <a class="code" href="structnih_1_1_histogram.html#aad9fcd509dfb9867bef691171eeddf07">std::max</a>( <span class="keywordtype">double</span>(m_stats.<a class="code" href="structnih_1_1_stats.html#a731ffdbad86052f9189e5dd7f89dcaba">max</a>() - m_stats.<a class="code" href="structnih_1_1_stats.html#a9004ea55168fe069477102bbc326fd30">min</a>()), 1.0e-8 );
<a name="l00153"></a>00153                 <span class="keyword">const</span> uint32 b = <a class="code" href="structnih_1_1_histogram.html#a34b0697ee7f959f9b581f18bbecfba32">std::min</a>( uint32(x), (uint32)m_bins.size()-1 );
<a name="l00154"></a>00154                 <span class="keywordflow">return</span> b;
<a name="l00155"></a>00155         }
<a name="l00159"></a><a class="code" href="structnih_1_1_histogram.html#a7b0fc3739f04f28b32fb11dbaec17a98">00159</a>         T <a class="code" href="structnih_1_1_histogram.html#a7b0fc3739f04f28b32fb11dbaec17a98">bin_min</a>(<span class="keyword">const</span> uint32 b)<span class="keyword"> const</span>
<a name="l00160"></a>00160 <span class="keyword">        </span>{
<a name="l00161"></a>00161                 <span class="keywordflow">return</span> (m_stats.<a class="code" href="structnih_1_1_stats.html#a731ffdbad86052f9189e5dd7f89dcaba">max</a>() - m_stats.<a class="code" href="structnih_1_1_stats.html#a9004ea55168fe069477102bbc326fd30">min</a>()) * <span class="keywordtype">float</span>(b) / float(m_bins.size()) + m_stats.<a class="code" href="structnih_1_1_stats.html#a9004ea55168fe069477102bbc326fd30">min</a>();
<a name="l00162"></a>00162         }
<a name="l00166"></a><a class="code" href="structnih_1_1_histogram.html#ad81875d21a2c8e79bbb0890ab0e6a022">00166</a>         T <a class="code" href="structnih_1_1_histogram.html#ad81875d21a2c8e79bbb0890ab0e6a022">bin_max</a>(<span class="keyword">const</span> uint32 b)<span class="keyword"> const</span>
<a name="l00167"></a>00167 <span class="keyword">        </span>{
<a name="l00168"></a>00168                 <span class="keywordflow">return</span> (m_stats.<a class="code" href="structnih_1_1_stats.html#a731ffdbad86052f9189e5dd7f89dcaba">max</a>() - m_stats.<a class="code" href="structnih_1_1_stats.html#a9004ea55168fe069477102bbc326fd30">min</a>()) * <span class="keywordtype">float</span>(b+1) / float(m_bins.size()) + m_stats.<a class="code" href="structnih_1_1_stats.html#a9004ea55168fe069477102bbc326fd30">min</a>();
<a name="l00169"></a>00169         }
<a name="l00170"></a>00170 
<a name="l00174"></a><a class="code" href="structnih_1_1_histogram.html#a93fd01eeb1081763157d7da55acdf0ae">00174</a>         <span class="keywordtype">void</span> <a class="code" href="structnih_1_1_histogram.html#a93fd01eeb1081763157d7da55acdf0ae">operator+= </a>(<span class="keyword">const</span> T v)
<a name="l00175"></a>00175         {
<a name="l00176"></a>00176                 uint32 b = <a class="code" href="structnih_1_1_histogram.html#a2019e21e8331552e11868f2ebb7e88ed">bin</a>( v );
<a name="l00177"></a>00177                 m_bins[b] += v;
<a name="l00178"></a>00178                 m_var += (v - m_stats.<a class="code" href="structnih_1_1_stats.html#af01f7f8dd7a128d55d408481e72d6615">avg</a>()) * (v - m_stats.<a class="code" href="structnih_1_1_stats.html#af01f7f8dd7a128d55d408481e72d6615">avg</a>());
<a name="l00179"></a>00179         }
<a name="l00180"></a>00180 
<a name="l00184"></a><a class="code" href="structnih_1_1_histogram.html#af5ea4cf95bd6f513637185ef459227ed">00184</a>         T                       <a class="code" href="structnih_1_1_histogram.html#af5ea4cf95bd6f513637185ef459227ed">avg</a>(<span class="keyword">const</span> uint32 b)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_bins[b].avg(); }
<a name="l00188"></a><a class="code" href="structnih_1_1_histogram.html#ac11bb3aaf34b80cf1b0197cfaec6ad13">00188</a>         T                       <a class="code" href="structnih_1_1_histogram.html#ac11bb3aaf34b80cf1b0197cfaec6ad13">sum</a>(<span class="keyword">const</span> uint32 b)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_bins[b].sum(); }
<a name="l00192"></a><a class="code" href="structnih_1_1_histogram.html#a34b0697ee7f959f9b581f18bbecfba32">00192</a>         T                       <a class="code" href="structnih_1_1_histogram.html#a34b0697ee7f959f9b581f18bbecfba32">min</a>(<span class="keyword">const</span> uint32 b)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_bins[b].min(); }
<a name="l00196"></a><a class="code" href="structnih_1_1_histogram.html#aad9fcd509dfb9867bef691171eeddf07">00196</a>         T                       <a class="code" href="structnih_1_1_histogram.html#aad9fcd509dfb9867bef691171eeddf07">max</a>(<span class="keyword">const</span> uint32 b)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_bins[b].max(); }
<a name="l00200"></a><a class="code" href="structnih_1_1_histogram.html#a93961d96035232c3a8068188c5b94478">00200</a>         <span class="keywordtype">long</span> <span class="keywordtype">long</span>       <a class="code" href="structnih_1_1_histogram.html#a93961d96035232c3a8068188c5b94478">count</a>(<span class="keyword">const</span> uint32 b)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_bins[b].count(); }
<a name="l00204"></a><a class="code" href="structnih_1_1_histogram.html#add147c7cfa62c368150ef680a243e9f3">00204</a>         <span class="keywordtype">float</span>           <a class="code" href="structnih_1_1_histogram.html#add147c7cfa62c368150ef680a243e9f3">percentage</a>(<span class="keyword">const</span> uint32 b)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> float( m_bins[b].<a class="code" href="structnih_1_1_histogram.html#a93961d96035232c3a8068188c5b94478">count</a>() ) / float( m_stats.<a class="code" href="structnih_1_1_stats.html#a5e68da5d70cd31130bca00c4224fe740">count</a>() ); }
<a name="l00207"></a><a class="code" href="structnih_1_1_histogram.html#af8d91f889c49450bddc82c87c96fc60b">00207</a>         T                       <a class="code" href="structnih_1_1_histogram.html#af8d91f889c49450bddc82c87c96fc60b">var</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_var / <a class="code" href="structnih_1_1_histogram.html#aad9fcd509dfb9867bef691171eeddf07">std::max</a>( (<span class="keywordtype">float</span>)m_stats.<a class="code" href="structnih_1_1_stats.html#a5e68da5d70cd31130bca00c4224fe740">count</a>(), 1.0f ); }
<a name="l00210"></a><a class="code" href="structnih_1_1_histogram.html#afbcee663ea55aa97115f4f8ef1bde8a1">00210</a>         T                       <a class="code" href="structnih_1_1_histogram.html#afbcee663ea55aa97115f4f8ef1bde8a1">sigma</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> T( sqrt( <a class="code" href="structnih_1_1_histogram.html#af8d91f889c49450bddc82c87c96fc60b">var</a>() ) ); }
<a name="l00211"></a>00211 
<a name="l00212"></a>00212         Stats_type                              m_stats;
<a name="l00213"></a>00213         std::vector&lt;Stats_type&gt; m_bins;
<a name="l00214"></a>00214         T                                               m_var;
<a name="l00215"></a>00215 };
<a name="l00216"></a>00216 
<a name="l00220"></a><a class="code" href="classnih_1_1_running_stat.html">00220</a> <span class="keyword">class </span><a class="code" href="classnih_1_1_running_stat.html">RunningStat</a>
<a name="l00221"></a>00221 {
<a name="l00222"></a>00222 <span class="keyword">public</span>:
<a name="l00225"></a><a class="code" href="classnih_1_1_running_stat.html#a7552ff4ea8100a6c2a4116406d7cb4a4">00225</a>     NIH_HOST_DEVICE <a class="code" href="classnih_1_1_running_stat.html#a7552ff4ea8100a6c2a4116406d7cb4a4">RunningStat</a>() : m_n(0) {}
<a name="l00226"></a>00226 
<a name="l00229"></a><a class="code" href="classnih_1_1_running_stat.html#a089b7318809b0b6465f0cde8bb506a9e">00229</a>     NIH_HOST_DEVICE <span class="keywordtype">void</span> <a class="code" href="classnih_1_1_running_stat.html#a089b7318809b0b6465f0cde8bb506a9e">clear</a>()
<a name="l00230"></a>00230     {
<a name="l00231"></a>00231         m_n = 0;
<a name="l00232"></a>00232     }
<a name="l00233"></a>00233 
<a name="l00237"></a><a class="code" href="classnih_1_1_running_stat.html#a5569aae5076f40ac16889e5b7f5c1564">00237</a>     NIH_HOST_DEVICE <span class="keywordtype">void</span> <a class="code" href="classnih_1_1_running_stat.html#a5569aae5076f40ac16889e5b7f5c1564">push</a>(<span class="keywordtype">float</span> x)
<a name="l00238"></a>00238     {
<a name="l00239"></a>00239         m_n++;
<a name="l00240"></a>00240 
<a name="l00241"></a>00241         <span class="comment">// See Knuth TAOCP vol 2, 3rd edition, page 232</span>
<a name="l00242"></a>00242         <span class="keywordflow">if</span> (m_n == 1)
<a name="l00243"></a>00243         {
<a name="l00244"></a>00244             m_oldM = m_newM = x;
<a name="l00245"></a>00245             m_oldS = 0.0;
<a name="l00246"></a>00246         }
<a name="l00247"></a>00247         <span class="keywordflow">else</span>
<a name="l00248"></a>00248         {
<a name="l00249"></a>00249             m_newM = m_oldM + (x - m_oldM)/m_n;
<a name="l00250"></a>00250             m_newS = m_oldS + (x - m_oldM)*(x - m_newM);
<a name="l00251"></a>00251 
<a name="l00252"></a>00252             <span class="comment">// set up for next iteration</span>
<a name="l00253"></a>00253             m_oldM = m_newM; 
<a name="l00254"></a>00254             m_oldS = m_newS;
<a name="l00255"></a>00255         }
<a name="l00256"></a>00256     }
<a name="l00257"></a>00257 
<a name="l00260"></a><a class="code" href="classnih_1_1_running_stat.html#acad1d887fa5d96d4f44fa22e7d572d67">00260</a>     NIH_HOST_DEVICE <span class="keywordtype">int</span> <a class="code" href="classnih_1_1_running_stat.html#acad1d887fa5d96d4f44fa22e7d572d67">count</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_n; }
<a name="l00261"></a>00261 
<a name="l00264"></a><a class="code" href="classnih_1_1_running_stat.html#a8785bce54f320d8a74aff13407f70fab">00264</a>     NIH_HOST_DEVICE <span class="keywordtype">float</span> <a class="code" href="classnih_1_1_running_stat.html#a8785bce54f320d8a74aff13407f70fab">mean</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> (m_n &gt; 0) ? m_newM : 0.0f; }
<a name="l00265"></a>00265 
<a name="l00268"></a><a class="code" href="classnih_1_1_running_stat.html#a793cbce3c688d017aa1411b73211fa31">00268</a>     NIH_HOST_DEVICE <span class="keywordtype">float</span> <a class="code" href="classnih_1_1_running_stat.html#a793cbce3c688d017aa1411b73211fa31">variance</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> ( (m_n &gt; 1) ? m_newS/(m_n - 1) : 0.0f ); }
<a name="l00269"></a>00269 
<a name="l00270"></a>00270 <span class="keyword">private</span>:
<a name="l00271"></a>00271     <span class="keywordtype">int</span> m_n;
<a name="l00272"></a>00272     <span class="keywordtype">float</span> m_oldM, m_newM, m_oldS, m_newS;
<a name="l00273"></a>00273 };
<a name="l00274"></a>00274 
<a name="l00275"></a>00275 } <span class="comment">// namespace nih</span>
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="stats_8h.html">stats.h</a>      </li>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>


    <li class="footer">Generated on Thu Dec 15 2011 11:56:19 for nih by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
